//
//  LineBt.m
//  快踩黑块儿
//
//  Created by Darry on 15/3/7.
//  Copyright (c) 2015年 戴. All rights reserved.
//

#import "LineBt.h"

@interface LineBt ()
{
    BOOL _blackline[4];
}

@end
@implementation LineBt

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
       
//          [self blackRandom];
//        for (int i = 0; i<4; i++) {
//            self->bt[i] = [UIButton buttonWithType:UIButtonTypeSystem];
//            bt[i].frame = CGRectMake(0+i, 0, 80, 142);
//          
//            if (_blackline[i]) {
//                bt[i].backgroundColor = [UIColor blackColor];
//            }else bt[i].backgroundColor = [UIColor blackColor];
//            [self addSubview:bt[i]];
//            [bt[i] release];
//        }
        
//        for (int i = 0; i<4; i++) {
//            self->bt[i] = [UIButton buttonWithType:UIButtonTypeSystem];
//            bt[i].frame = CGRectMake(0+i, 0, 80, 142);
//            bt[i].backgroundColor = [UIColor blackColor];
//            [self addSubview:bt[i]];
//            [bt[i] release];
//        }
        self.bt1 = [MyButton buttonWithType:UIButtonTypeSystem];
        _bt1.frame = CGRectMake(0, 0, 80, 142);
        _bt1.backgroundColor = [UIColor whiteColor];
        _bt1.black = NO;
        [self addSubview:_bt1];
        [_bt1 release];

        self.bt2 = [MyButton buttonWithType:UIButtonTypeSystem];
        _bt2.frame = CGRectMake(80, 0, 80, 142);
        _bt2.backgroundColor = [UIColor whiteColor];
        _bt2.black = NO;
        [self addSubview:_bt2];
        [_bt2 release];

        self.bt3 = [MyButton buttonWithType:UIButtonTypeSystem];
        _bt3.frame = CGRectMake(160, 0, 80, 142);
        _bt3.backgroundColor = [UIColor whiteColor];
        _bt3.black = NO;
        [self addSubview:_bt3];
        [_bt3 release];

        self.bt4 = [MyButton buttonWithType:UIButtonTypeSystem];
        _bt4.frame = CGRectMake(240, 0, 80, 142);
        _bt4.backgroundColor = [UIColor whiteColor];
        _bt4.black = NO;
//        [_bt4 addTarget:self action:@selector(bingo:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_bt4];
        [_bt4 release];

        
        
    }
    return self;
}
//在4个0元素的数组中 选择一个赋值为1
-(void)blackRandom{
    for (int i = 0; i<4; i++) {
        _blackline[i] = NO;
    }
    int r = arc4random() % 4;
    _blackline[r] = YES;
}
//在一行的4个白块中随机生成1个黑块
-(void)changeblack{
    [self blackRandom];
        if (_blackline[0]) {
            _bt1.backgroundColor = [UIColor blackColor];
            _bt1.black = YES;
        }
    if (_blackline[1]) {
        _bt2.backgroundColor = [UIColor blackColor];
        _bt2.black = YES;
    }
    if (_blackline[2]) {
        _bt3.backgroundColor = [UIColor blackColor];
        _bt3.black = YES;
    }
    if (_blackline[3]) {
        _bt4.backgroundColor = [UIColor blackColor];
        _bt4.black = YES;
    }
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
